package servlet;

import bean.Users;
import service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/getallusers")
public class ShowUsersServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UsersServiceImpl usersService = new UsersServiceImpl();
        List<Users> usersList = usersService.getAllUsers();
        //设置编码

        //将数据库中取出来的信息存储，供前端取用
        req.setAttribute("users",usersList);
        req.setCharacterEncoding("utf-8");
        req.getRequestDispatcher("showAllUsers.jsp").forward(req,resp);

    }
}
